/*
 * 类名称:EnterpriseInspectorController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-09-25 19:51:13        hww     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.SysLog;
import com.platform.entity.FireExtinguisherEntity;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import com.platform.controller.AbstractController;
import com.platform.entity.EnterpriseInspectorEntity;
import com.platform.service.EnterpriseInspectorService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 企业巡查员Controller
 *
 * @author hww
 * @date 2019-09-25 19:51:13
 */
@RestController
@RequestMapping("fs/enterpriseinspector")
public class EnterpriseInspectorController extends AbstractController {
    @Autowired
    private EnterpriseInspectorService enterpriseInspectorService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @IgnoreAuth
//    @RequiresPermissions("fs:enterpriseinspector:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<EnterpriseInspectorEntity> list = enterpriseInspectorService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询企业巡查员
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
//    @RequiresPermissions("fs:enterpriseinspector:list")
    public R list(@RequestParam Map<String, Object> params) {
//        Page page = enterpriseInspectorService.queryPage(params);
//
//        return R.ok().put("page", page);

        //查询列表数据
//        Query query = new Query(params);
//
//        List<EnterpriseInspectorEntity> userLevelList = enterpriseInspectorService.queryList(query);
//        int total = enterpriseInspectorService.queryTotal(query);
//
//        PageUtils pageUtil = new PageUtils(userLevelList, total, query.getLimit(), query.getPage());
//
//        return R.ok().put("page", pageUtil);

        ////////////////////////////////////////////////////////////

        Page page = enterpriseInspectorService.queryPage(params);
        List<FireExtinguisherEntity> list = page.getRecords();
        int total = (int)page.getTotal();//;
        int pageNum = (int)page.getCurrent();//
        int limit = (int)page.getSize();
        PageUtils pageUtil = new PageUtils(list,total,limit,pageNum);
        return R.ok().put("page", pageUtil);

    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("fs:enterpriseinspector:info")
    public R info(@PathVariable("id") String id) {
        EnterpriseInspectorEntity enterpriseInspector = enterpriseInspectorService.getById(id);

        return R.ok().put("enterpriseInspector", enterpriseInspector);
    }

    /**
     * 新增企业巡查员
     *
     * @param enterpriseInspector enterpriseInspector
     * @return R
     */
    @SysLog("新增企业巡查员")
    @RequestMapping("/save")
//    @RequiresPermissions("fs:enterpriseinspector:save")
    public R save(@RequestBody EnterpriseInspectorEntity enterpriseInspector) {
        enterpriseInspector.setId(UUID.randomUUID().toString());
        enterpriseInspector.setCreateTime(new Date());
        enterpriseInspector.setCreateUser("黄某某");
        enterpriseInspectorService.add(enterpriseInspector);

        return R.ok();
    }

    /**
     * 修改企业巡查员
     *
     * @param enterpriseInspector enterpriseInspector
     * @return R
     */
    @SysLog("修改企业巡查员")
    @RequestMapping("/update")
//    @RequiresPermissions("fs:enterpriseinspector:update")
    public R update(@RequestBody EnterpriseInspectorEntity enterpriseInspector) {

        enterpriseInspectorService.update(enterpriseInspector);

        return R.ok();
    }

    /**
     * 根据主键删除企业巡查员
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除企业巡查员")
    @RequestMapping("/delete")
//    @RequiresPermissions("fs:enterpriseinspector:delete")
    public R delete(@RequestBody String[] ids) {
        enterpriseInspectorService.deleteBatch(ids);

        return R.ok();
    }
}
